#include <iostream>
#include <string>
#include "log.hpp"
#include "command_excute.hpp"
#include "tcp_serve.hpp"

void Usage(std::string name)
{
   std::cout << "usage:\n\t" << name << " local_port\n"
             << std::endl;
}
int main(int argc, char *argv[])
{
   if (argc != 2)
   {
      Usage(argv[0]);
      return 1;
   }
   EnableScrean();                                                                 // 开启屏幕日志
   uint16_t port = std::stoi(argv[1]);                                             // 端口号
   Command cmd("./safe.txt");                                                      // 创建Command对象
   func_t excute_t = bind(&Command::excute, &cmd, std::placeholders::_1);          // 将excute函数绑定到cmd对象，并指定一个占位符
   std::unique_ptr<tcp_serve> t_ptr = std::make_unique<tcp_serve>(port, excute_t); // 创建智能指针指向tcp_serve类，并构造类对象
   t_ptr->init_serve();
   t_ptr->loop();
   return 0;
}